package com.wxp.demo03.align;

import android.os.Bundle;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.wxp.demo03.R;
import com.wxp.demo03.util.PxUtils;

/**
 * 2.1设置视图的宽高
 */
public class ViewBorderActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        this.setTitle("2.1设置视图的宽高");
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_view_border);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.view_border), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        //设置控件宽度
        TextView textView = findViewById(R.id.textView10);
        //注意：默认单位为px,需要对输入的值进行转换
        textView.setWidth(PxUtils.dipToPx(this, 200));

    }
}